package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.dao.addCoupons;
import com.hzy.fivepalace.admin.service.AdminCouponService;
import com.hzy.fivepalace.common.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;


@RestController
@RequestMapping("/admin/coupon")
@Validated
@Api(tags = "优惠券服务")
@Login
public class AdminCouponController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(AdminCouponController.class);

    @Resource
    private AdminCouponService adminCouponService;

    /**
     * 优惠券列表
     *
     * @param couponsName
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/couponsList/v1_0_0")
    @ApiOperation(value = "优惠券列表")
    public TableDataInfo couponsList(
            @ApiParam(value = "检索用:优惠券名称") @RequestParam(value = "couponsName", defaultValue = "", required = false) String couponsName,
            @ApiParam(value = "页码", defaultValue = "1", required = true) @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10", required = true) @RequestParam(defaultValue = "10") Integer size
    ) {

        return adminCouponService.getCouponsList(page, size, couponsName);
    }

    @PostMapping("/getUserCouponsList")
    @ApiOperation(value = "用户优惠券列表")
    public TableDataInfo getActivityList(
            @ApiParam(value = "用户id:可对单个用户查询") @RequestParam(value = "userId", required = false) Integer userId,
            @ApiParam(value = "优惠券id:这里是优惠券列表返回的id,可针对某张优惠券查询") @RequestParam(value = "id", required = false) Integer id,
            @ApiParam(value = "状态：0未使用，1已失效") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size
    ) {

        return adminCouponService.getUserCouponsList(page, size, status, userId, id);
    }

    /**
     * 派发优惠券-单个
     *
     * @param userId
     * @param id
     * @return
     */
    @PostMapping("/payoutCouponsSingle")
    @ApiOperation(value = "派发优惠券-单个")
    public Object payoutCouponsSingle(
            @ApiParam(value = "用户id") @RequestParam(value = "userId") @NotNull Integer userId,
            @ApiParam(value = "优惠券id:这里是优惠券列表返回的id") @RequestParam(value = "id") @NotNull Integer id) {

        return adminCouponService.payoutCouponsSingle(userId, id);
    }

    /**
     * 派发优惠券-单个
     *
     * @param id
     * @return
     */
    @PostMapping("/payoutCouponsAll")
    @ApiOperation(value = "派发优惠券-所有")
    public Object payoutCouponsAll(
            @ApiParam(value = "优惠券id:这里是优惠券列表返回的id") @RequestParam(value = "id") @NotNull Integer id) {

        return adminCouponService.payoutCouponsAll(id);
    }

    /**
     * 作废已派发未使用的优惠券
     *
     * @param id
     * @return
     */
    @PostMapping("/withdrawAllPayout")
    @ApiOperation(value = "作废已派发未使用的优惠券")
    public Object withdrawAllPayout(
            @ApiParam(value = "优惠券id:这里是优惠券列表返回的id") @RequestParam(value = "id") @NotNull Integer id) {

        return adminCouponService.withdrawAllPayout(id);
    }

    @PostMapping("/addCoupons")
    @ApiOperation(value = "新增优惠券")
    public Object addCoupons(
            addCoupons dto
    ) {

        return adminCouponService.addCoupons(dto);
    }


}
